package com.example.zuul;

import org.springframework.web.context.request.async.DeferredResult;
import rx.Observable;
import rx.Observer;

import java.util.HashMap;

@org.springframework.web.bind.annotation.RestController
public class RestController {


    public Observable<HashMap<String, String>> aggregateObservable(Long id) {
        // 合并两个或者多个Observables发射出的数据项，根据指定的函数变换它们
   /*     return Observable.zip ("","",(t1, t2) -> {
            return Ob;
        });*/
        return null;
    }

    public DeferredResult<HashMap<String, String>> toDeferredResult(Observable<HashMap<String, String>> details) {
        DeferredResult<HashMap<String, String>> result = new DeferredResult<>();
        // 订阅
        details.subscribe(new Observer<HashMap<String, String>>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable throwable) {

            }

            @Override
            public void onNext(HashMap<String, String> movieDetails) {
                result.setResult(movieDetails);
            }
        });
        return result;

    }
}
